import { Component, Input, OnInit } from '@angular/core';
import { Hero } from './app.hero';
import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/common';
import { HeroService } from './hero.service';

import 'rxjs/add/operator/switchMap';

@Component({
    selector: 'app-herodetail',
    templateUrl: './app.herodetail.component.html',
    styleUrls: ['./app.component.css']
})

export class HeroDetailComponent implements OnInit {
    @Input() chero: Hero;

    constructor(private heroService: HeroService,
        private route: ActivatedRoute,
        private location: Location) {

    }

    ngOnInit() {
        this.route.params.subscribe((params: Params) => {
            this.heroService.getHero(+params['id']).then((hero) => {
                this.chero = hero;
            });
        })
    }

    goBack() {
        this.location.back();
    }


}




